{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>编辑</h5>
                </div>
                <div class="ibox-content layui-form">
                    <div class="layui-row layui-col-space10 layui-form-item ">
                        <input type="hidden" name="id" value="{$id}">
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">经销商名称：</label>
                            <div class="layui-input-block">
                                <input type="text" name="dealer_name" value="{$info.dealer_name}" lay-verify="required" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">经销商电话：</label>
                            <div class="layui-input-block">
                                <input type="text" name="dealer_phone"value="{$info.dealer_phone}" lay-verify="required" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">车系：</label>
                            <div class="layui-input-block">
                                <select name="dealer_car_id" xm-select="select1" lay-verify="required" xm-select-radio=""  xm-select-search="" xm-select-search-type="dl">
                                    {foreach name="series" item="v"}
                                    <option value="{$v.cs_id}" {$v.cs_id==$info.dealer_car_id?'selected':''}>{$v.cs_name}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">省：</label>
                            <div class="layui-input-block">
                                <select name="province" lay-search="" id="province"  lay-filter="province">
                                    <option value="">---- 请选择省 ----</option>
                                    {foreach name="province" item="vo"}
                                    <option value="{$vo.district_id}" {if $vo['district_id']==$info['dealer_sheng']} selected {/if}>{$vo.district}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">市：</label>
                            <div class="layui-input-block">
                                <select name="city" lay-search=""  id="city"  lay-filter="city">
                                <option value="">---- 请选择市 ----</option>
                                {foreach name="city" item="vo1"}
                                <option value="{$vo1.district_id}" {if $vo1['district_id']==$info['dealer_shi']} selected {/if}>{$vo1.district}</option>
                                {/foreach}
                                </select>

                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">区：</label>
                            <div class="layui-input-block">
                                <select name="district" lay-search=""  id="district"  lay-filter="district">
                                <option value="">---- 请选择区----</option>
                                {foreach name="qu" item="vo2"}
                                <option value="{$vo2.district_id}" {if $vo2['district_id']==$info['dealer_qu']} selected {/if}>{$vo2.district}</option>
                                {/foreach}
                                </select>

                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8" style="margin-top:100px">
                            <label class="layui-form-label">定位的地址:</label>
                            <div class="layui-input-block">
                                <div id="container" style='width:90%;height:400px;z-index: 100;'></div>
                                <div id="myPageTop" style="margin-left: 150px;margin-top:10px;z-index:1000" >
                                    <table>
                                        <tr>
                                            <td>
                                                <label>请输入搜索内容</label>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <input id="tipinput" class="dingwei" style="position: absolute;top: 0;right: -120px" placeholder="请输入地址"/>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">定位的地址:</label>
                            <div class="layui-input-block">
                                <table style="border-collapse:separate; border-spacing:5px;">
                                    <tr>
                                        <td>
                                            <input type="text"  value="{$info.dealer_address}" name="activity_address" class="activity_address" style="height:30px;width:500px" placeholder="详情地址" value=""/>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <input type="text"  value="{$info.dealer_lon}" readonly name="longitude" class="longitude" style="height:30px" placeholder="经度" value=""/>
                                        </td>
                                        <td>
                                            <input type="text"  value="{$info.dealer_lat}"  readonly name="latitude" class="latitude" style="margin-left:-250px;height:30px" placeholder="纬度" value=""/>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" lay-filter="component-form-element">编辑
                                </button>
                                <button class="layui-btn layui-btn-primary" onclick="history.go(-1)">关闭</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=f54db2291954fee8b16d8b6b6c4a5ab3&plugin=AMap.Autocomplete,AMap.PlaceSearch,AMap.Geocode"></script>
<script type="text/javascript">

    var map = new AMap.Map("container", {
        resizeEnable: true
    });

    var autoOptions = {
        input: "tipinput"
    };

    var auto = new AMap.Autocomplete(autoOptions);
    var placeSearch = new AMap.PlaceSearch({
        map: map
    });
    AMap.event.addListener(auto, "select", select);
    function select(e) {
//        console.log(e);
        placeSearch.setCity(e.poi.adcode);
        placeSearch.search(e.poi.name);
        var lng = e.poi.location.lng;   //获取经度
        var lat = e.poi.location.lat;   //获取纬度
        var address = e.poi.district+e.poi.name;   //获取纬度
        $('input[name=activity_address]').val(address);
        $('input[name=longitude]').val(lng);
        $('input[name=latitude]').val(lat);
//        console.log(address);
//        console.log(lng);
//        console.log(lat);
    }
    AMap.event.addListener(placeSearch, "markerClick", addasd)

    function addasd(e) {
//        console.log(e);
//        console.log(e.data.location.lng);
//        console.log(e.data.location.lat);
        $('input[name=activity_address]').val(e.data.pname+e.data.cityname+e.data.adname+e.data.name);
        $('input[name=longitude]').val(e.data.location.lng);
        $('input[name=latitude]').val(e.data.location.lat);
//        console.log(e.data.pname+e.data.cityname+e.data.adname+e.data.name);
    }

</script>
<script>
    //    var editor = wk.wang({elem:'#LAY_editor'});
    //    wk.uploadImg({size:5,type:'png,jpg,jpeg',url:"{:url('Upload/upload')}",domain:""});
    layui.use(['form','upload','layedit'], function() {
        var form = layui.form;
//        form.verify({
//            editor:function(value,item){
//                if(editor.txt.html() == '<p><br></p>'){
//                    return '请填写内容';
//                }
//            }
//        });
        form.on('submit(component-form-element)', function (data) {
//            data.field.lunbo_content = editor.txt.html();
            $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            $.ajax({
                url:"{:url('update')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    if (res.code == 200) {
                        wk.success(res.msg,"{:url('dealer/index')}")
                    } else {
                        wk.error(res.msg,'','$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\');');
                    }
                }
            })
        });

    });
</script>

</body>
</html>
